package 二叉树相关问题.中度题;

public class 树的子结构 {
    public boolean isSubStructure(TreeNode A, TreeNode B) {
        if (A==null || B==null)
            return false;
       return bfs(A,B) || isSubStructure(A.left,B) || isSubStructure(A.right,B);
    }
    public boolean bfs(TreeNode A, TreeNode B) {
        if (B==null)
            return true;
        if (A==null)
            return false;
        return A.val==B.val && bfs(A.left,B.left) && bfs(A.right,B.right);
    }
}
